//
//  ByRecordHeadView.m
//  recordworktool_ios
//
//  Created by mc on 2017/12/4.
//  Copyright © 2017年 ZhangZhanbin. All rights reserved.
//

#import "ByRecordHeadView.h"

@implementation ByRecordHeadView

- (id)init{
    self = [super init];
    if (self){
        
        
        
        
    }
    return self;
}

- (void)setIsWorker:(BOOL)isWorker{
    
    NSArray *itemsAry;
    if (isWorker){
        itemsAry = @[@"点工",@"包工",@"借支",@"结算"];
    }else{
        itemsAry = @[@"记点工",@"记包工",@"借支",@"结算"];
    }
    self.backgroundColor = [UIColor whiteColor];
    CGFloat magin = 15;
    CGFloat width = (SCREEN_WIDTH - magin * 5) / 4.0;
    
    for (int i = 0; i < itemsAry.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:btn];
        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self).offset(0);
            make.left.equalTo(self).offset((i + 1) * magin + i * width);
            make.size.mas_equalTo(CGSizeMake(width, 35));
        }];
        [btn setTitle:itemsAry[i] forState:UIControlStateNormal];
        btn.titleLabel.font = FONT(15);
        [btn setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor whiteColor];
        btn.layer.borderColor = BY_THEME_COLOR.CGColor;
        btn.layer.borderWidth = 1;
        btn.layer.cornerRadius = 17.5;
        btn.tag = 100 + i;
        [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        if (i == 0) {
            btn.selected = YES;
            btn.backgroundColor = BY_THEME_COLOR;
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }
        
    }
}

- (void)btnAction:(UIButton *)btn{
    if (btn.selected) {
        return;
    }
    for (UIButton *button in self.subviews) {
        button.selected = NO;
        button.backgroundColor = [UIColor whiteColor];
        [button setTitleColor:BY_THEME_COLOR forState:UIControlStateNormal];
    }
    btn.backgroundColor = BY_THEME_COLOR;
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.selected = YES;
    self.indexAtView(btn.tag - 100);
}



@end
